﻿using System;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace UpwardsTimeClock.Prototype
{
    #region Abstract Class

    public abstract partial class Component: IDisposable
    {
        [XmlIgnore]
        public bool IsInitialized { get; private set; }

        [XmlIgnore]
        public ControlBase Control { get; private set; }

        protected abstract ControlBase CreateControl();

        public void Initialize(System.Windows.Forms.Control.ControlCollection controls)
        {
            if (!IsInitialized)
            {
                Control = CreateControl();
                Control.Initialize(controls);
                IsInitialized = true;
            }
        }

        #region IDisposable Members

        public virtual void Dispose()
        {
            if (Control != null) Control.Dispose();
        }

        public void Reset()
        {
            if (Control != null) Control.Reset();
        }

        #endregion
    }

    public abstract partial class Startable
    {
        public abstract void Start();
    }

    public abstract partial class Spanning
    {
        public abstract void Stop();
        public abstract void TimerTick();
    }

    public abstract partial class Visual
    {

    }

    #endregion

    #region Concrete Classes

    public partial class Graphic
    {
        [XmlIgnore]
        public GraphicControl MyControl { get { return Control as GraphicControl; } }

        protected override ControlBase CreateControl()
        {
            return new GraphicControl(this);
        }

        public override void Start()
        {
            MyControl.Start();
        }

        public override void Stop()
        {
            MyControl.Stop();
        }

        public override void TimerTick()
        {
            MyControl.Timer();
        }
    }

    public partial class Video
    {
        [XmlIgnore]
        public VideoControl MyControl { get { return Control as VideoControl; } }

        protected override ControlBase CreateControl()
        {
            return new VideoControl(this);
        }

        public override void Start()
        {
            MyControl.Start();
        }

        public override void Stop()
        {
            MyControl.Stop();
        }

        public override void TimerTick()
        {
            MyControl.Timer();
        }
    }

    public partial class Sound
    {
        [XmlIgnore]
        public SoundControl MyControl { get { return Control as SoundControl; } }

        protected override ControlBase CreateControl()
        {
            return new SoundControl(this);
        }

        public override void Start()
        {
            MyControl.Start();
        }
    }

    public partial class Label
    {
        [XmlIgnore]
        public LabelControl MyControl { get { return Control as LabelControl; } }

        protected override ControlBase CreateControl()
        {
            return new LabelControl(this);
        }

        public override void Start()
        {
            MyControl.Start();
        }

        public override void Stop()
        {
            MyControl.Stop();
        }

        public override void TimerTick()
        {
            MyControl.Timer();
        }
    }

    public partial class AlternatingLabel
    {
        [XmlIgnore]
        public new AlternatingLabelControl MyControl { get { return Control as AlternatingLabelControl; } }

        protected override ControlBase CreateControl()
        {
            return new AlternatingLabelControl(this);
        }

        public override void Start()
        {
            MyControl.Start();
        }

        public override void Stop()
        {
            MyControl.Stop();
        }

        public override void TimerTick()
        {
            MyControl.Timer();
        }
    }

    public partial class Clock
    {
        [XmlIgnore]
        public new ClockControl MyControl { get { return Control as ClockControl; } }

        protected override ControlBase CreateControl()
        {
            return new ClockControl(this);
        }

        public override void Start()
        {
            MyControl.Start();
        }

        public override void Stop()
        {
            MyControl.Stop();
        }

        public override void TimerTick()
        {
            MyControl.Timer();
        }
    }

    public partial class Timer
    {
        [XmlIgnore]
        public new TimerControl MyControl { get { return Control as TimerControl; } }

        protected override ControlBase CreateControl()
        {
            return new TimerControl(this);
        }

        public override void Start()
        {
            MyControl.Start();
        }

        public override void Stop()
        {
            MyControl.Stop();
        }

        public override void TimerTick()
        {
            MyControl.Timer();
        }
    }

    #endregion
}
